package com.zhanghe.study.springmvc.controller.session;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 测试spring-session
 * @author zh
 * @date 2021/6/15 14:12
 */
@RestController
@RequestMapping("/ss")
public class SpringSessionController {

    @RequestMapping("/addSession")
    public void addSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String name = request.getParameter("name");
        String value = request.getParameter("value");
        session.setAttribute(name,value);
    }

    @RequestMapping("/getSession")
    public String getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String name = request.getParameter("name");
        return (String) session.getAttribute(name);
    }

    @RequestMapping("/removeSession")
    public void removeSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String name = request.getParameter("name");
        session.removeAttribute(name);
    }
}
